package com.metaera.app.ui.activities;

import android.os.Bundle;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.lxj.xpopup.XPopup;
import com.metaera.app.R;
import com.metaera.app.controller.core.IPaginationPresenter;
import com.metaera.app.controller.presenter.InvestFinanceListPresenter;
import com.metaera.app.controller.view.BasicPaginationView;
import com.metaera.app.controller.view.core.IPaginationView;
import com.metaera.app.data.model.InvestFinanceResponse;
import com.metaera.app.data.network.ApiParam;
import com.metaera.app.ui.adapters.InvestFinanceListAdapter;
import com.metaera.app.ui.core.BaseRequestActivity;
import com.metaera.app.ui.popup.SharePopup;
import com.metaera.app.utils.ViewUtils;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

import androidx.recyclerview.widget.RecyclerView;

/**
 * 投融资
 */
public class InvestFinanceActivity extends BaseRequestActivity {

    @Override
    protected void initStatusBar() {
        StatusBarUtil.setTranslucentForImageViewInFragment(this, 0, null);
        StatusBarUtil.setLightMode(this);
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_invest_finance;
    }

    @Override
    protected void initialize(Bundle savedInstanceState) {
        ViewUtils.addStatusBarHeightPadding(findViewById(R.id.layout_container));
        // find view
        TextView tvLoadMore = findViewById(R.id.tv_more);
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        SmartRefreshLayout refreshLayout = findViewById(R.id.smart_refresh_layout);

        // init view
        recyclerView.setAdapter(new InvestFinanceListAdapter());
        refreshLayout.setEnableRefresh(false);
        refreshLayout.setEnableLoadMore(false);

        // network
        IPaginationPresenter<IPaginationView<InvestFinanceResponse>, InvestFinanceResponse>
                presenter = new InvestFinanceListPresenter();
        presenter.setModelAndView(new BasicPaginationView<InvestFinanceResponse>(recyclerView, refreshLayout, this){
            @Override
            public void renderNoMore() {
                super.renderNoMore();
                tvLoadMore.setText(R.string.load_no_more);
            }
        });
        presenter.requestRefresh();

        // listener
        tvLoadMore.setOnClickListener(v -> presenter.requestLoadMore());
        findViewById(R.id.iv_arrow_back).setOnClickListener(v -> finish());

        findViewById(R.id.iv_share).setOnClickListener(v -> {
            new XPopup.Builder(v.getContext())
                    .asCustom(
                            new SharePopup(
                                    v.getContext(),
                                    "投融资",
                                    "",
                                    ApiParam.LINK_SHARE_1,
                                    R.drawable.a_ic_invest_bg
                            )
                    )
                    .show();
        });
    }

}
